define(['zepto', 'utils', 'JST', 'sui', 'submitForm'], function($, utils, JST){
  return {
    init: function(data) {
      this.courseRoundId = data.courseRoundId;
      this.weekId = data.weekId;
      this.initPage();
      this.initSubmit();
    },
    
    initPage: function() {
      $(document).on("change", "input[type='checkbox']", function() {
        if($(this).attr("checked")) {
          $(this).attr("checked", false)
        } 
      })
    },
    
    validateHomework: function() {
      var homeworkFrequency = $("input[name='homeworkFrequency']").val().trim();
      if(homeworkFrequency) {
        if(isNaN(homeworkFrequency) || homeworkFrequency < 0) {
          $.toast("家庭作业完成次数不能小于0");
          return false;
        } else {
          return true;
        }
      }
      
      if($("input[name='lissTypes']:checked").length > 0) {
        return true;
      }
      
      if($("input[name='otherLiss']").val().trim()) {
        return true;
      }
      
      if($("textarea[name='hit']").val().trim()) {
        return true;
      }

      if($("textarea[name='core']").val().trim()) {
        return true;
      }

      if($("textarea[name='hit']").val().trim()) {
        return true;
      }

      if($("textarea[name='remark']").val().trim()) {
        return true;
      }
      
      $.toast("家庭作业不能为空");
      return false;
    },
    
    validateSchedule: function() {
        var scheduleFrequency = $("input[name='scheduleFrequency']").val().trim();
        if(scheduleFrequency && !isNaN(scheduleFrequency)) {
          if(isNaN(scheduleFrequency) || scheduleFrequency < 0) {
            $.toast("门店训练完成次数不能小于0");
            return false;
          } else {
            return true;
          }
        }
        
        if($("input[name^='day']:checked").length > 0) {
          return true;
        }
        
        $.toast("门店训练不能为空");
        return false;
      },
    
    initSubmit: function() {
      var that = this;
      
      $(".save-button").on("click", function() {
        if(that.validateHomework() && that.validateSchedule()) {
          $('[type="submit"]').trigger("click");
        }
      })
      
      $("form").submitform({
        successUrl: $(".fs-header-small a").attr("href")
      })
    }
  }
})